package app.netant.finishbook.zadzs;

import org.jsoup.select.Elements;

import app.netant.book.base.BaseDetail;
/**
 * 
 * @author JiaJ
 *
 */
public class ZadzsDetail extends BaseDetail {

	public ZadzsDetail(String netSite) {
		super(netSite);
		this.preHref = "http://www.zadzs.com";
	}

	@Override
	public void analyseTitle() {
		Elements parts = this.select("body .g-doc .g-bdw .g-bd-large .g-mn .m-bookdetail .f-fl h3");
		if(parts.size()>0){
			String title = parts.get(0).attr("title");
			System.out.println("【Title】:"+title);
			this.entity.setNovelName(title);
			this.entity.setNovelFullName(title+".txt");
		}
		
		Elements parts1 = this.select("body .g-doc .g-bdw .g-bd-large .g-mn .m-bookdetail .f-fl h3 span a");
		if(parts1.size()>0){
			String writer = parts1.get(0).text();
			System.out.println("【Writer】:"+writer);
			this.entity.setNovelWriter(writer);
		}
	}

	@Override
	public void analyseTags() {
		Elements parts = this.select("body .g-doc .g-bdw .g-bd-large .g-mn .m-bookdetail .f-fl .m-bookstatus table tbody tr");
		for(int i=0;i<parts.size();i++){
			Elements childs = parts.get(i).children();
			if(childs.size() == 2){
				String tagName = childs.get(0).text();
				String tagValue = childs.get(1).text();
				if(tagName.endsWith("：")){
					tagName = tagName.substring(0,tagName.length()-1);
				}
				System.out.println("【Tag】:"+tagName+"="+tagValue);
				this.entity.setTag(tagName, tagValue);
			}
		}
	}

	@Override
	public void analyseMemo() {
		Elements parts = this.select("body .g-doc .g-bdw .g-bd-large .g-mn .m-chapter .contents");
		if(parts.size()>0){
			String memo = parts.get(0).text();
			System.out.println("【Memo】:"+memo);
			this.entity.setNovelMemo(memo);
		}
	}

	@Override
	public void analyseHref() {
		Elements parts = this.select("body .g-doc .g-bdw .g-bd-large .g-mn .m-bookdetail .f-fl .ops a");
		for(int i=0;i<parts.size();i++){
			String text = parts.get(i).text();
			if(text.startsWith("TXT")){
				String href = parts.get(i).attr("href");
				if(href.startsWith("/")){
					href = this.preHref + href;
				}
				System.out.println("【Href】:"+href);
				this.entity.setDownPath(href);
			}
		}
	}
	
	@Override
	public void analyseType() {
		Elements parts = this.select("body .g-doc .g-bdw .g-bd-large .m-breadcrumbs a");
		if(parts.size()>1){
			String type = parts.get(1).text();
			System.out.println("【Type】:"+type);
			this.entity.setNovelType(type);
		}
	}
	
	public static void main(String[] args) {
		ZadzsDetail detail = new ZadzsDetail("http://www.zadzs.com/txt/3547.html");
		detail.test();
	}



}
